package com.cennavi.bigdata.baotou.test;

import com.mongodb.*;

/**
 * Created by zuoweiguang on 2017/3/10.
 * 分析决策支持系统 - 指数分析预警模块
 * 程序类型：测试脚本
 * 功能：插入商圈、学校、医院、政府机构、公园、地铁的测试数据
 */
public class MakeExponentLocationTestData {

    private MongoClient mongoClient = null;
    private DB db = null;
    private DBCollection exponentRegionCol = null;

    public MakeExponentLocationTestData() {
        //获取 mongo 的连接
        ServerAddress serverAddress = new ServerAddress("123.207.109.239", 27017);
        mongoClient = new MongoClient(serverAddress);
        db = mongoClient.getDB("baotou_traffic");
            exponentRegionCol = db.getCollection("exponent_region");
    }

    public void makeTestData() {
        //商圈
        String data1 = "{\"region_type\": \"business\", \"name\": \"万达\", \"region\": null, \"offset\": 0.006, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.85379585621848,40.65907700480179]}}";

        String data2 = "{\"region_type\": \"business\", \"name\": \"包百\", \"region\": null, \"offset\": 0.007, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.81311850275296,40.6577310258553]}}";
        //学校
        String data3 = "{\"region_type\": \"school\", \"name\": \"包头钢铁职业技术学院\", \"region\": null, \"offset\": 0.0076, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.83610983417566,40.62450977037395]}}";

        //医院
        String data4 = "{\"region_type\": \"hospital\", \"name\": \"昆区医院\", \"region\": null, \"offset\": 0.003, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.81315244133305,40.66288492716518]}}";

        //政府机构
        String data5 = "{\"region_type\": \"government\", \"name\": \"包头市昆区交警大队\", \"region\": null, \"offset\": 0.003, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.84334621461977,40.6505034904078]}}";

        //公园
        String data6 = "{\"region_type\": \"hospital\", \"name\": \"劳动公园\", \"region\": null, \"offset\": 0.007, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.87555317081518,40.65854977433855]}}";

        //地铁
        String data7 = "{\"region_type\": \"subway\", \"name\": \"包钢站\", \"region\": null, \"offset\": 0.00550, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.78216715533483,40.65974709138365]}}";

        String data8 = "{\"region_type\": \"subway\", \"name\": \"三八路站\", \"region\": null, \"offset\": 0.00410, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.80121083232308,40.658832770681414]}}";

        String data9 = "{\"region_type\": \"subway\", \"name\": \"维多利站\", \"region\": null, \"offset\": 0.00240, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.8117055291803,40.65836555836023]}}";

        String data10 = "{\"region_type\": \"subway\", \"name\": \"林荫路站\", \"region\": null, \"offset\": 0.00200, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.8215762842749,40.65786657063873]}}";

        String data11 = "{\"region_type\": \"subway\", \"name\": \"民族西路\", \"region\": null, \"offset\": 0.00310, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.83102349382199,40.65735622202564]}}";

        String data12 = "{\"region_type\": \"subway\", \"name\": \"阿尔丁广场站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.84017802737799,40.65690050831515]}}";

        String data13 = "{\"region_type\": \"subway\", \"name\": \"银河广场站\", \"region\": null, \"offset\": 0.00200, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.85436743309538,40.65619092765709]}}";
        String data14 = "{\"region_type\": \"subway\", \"name\": \"幸福路站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.86872597938077,40.65550816355122]}}";
        String data15 = "{\"region_type\": \"subway\", \"name\": \"一宫站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.87855286410752,40.65497578817113]}}";
        String data16 = "{\"region_type\": \"subway\", \"name\": \"青山政府站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.89276427741652,40.647282061371186]}}";
        String data17 = "{\"region_type\": \"subway\", \"name\": \"会展中心站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.94744829962144,40.61789258565685]}}";
        String data18 = "{\"region_type\": \"subway\", \"name\": \"世纪西路站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.94746567268697,40.6179241568405]}}";
        String data19 = "{\"region_type\": \"subway\", \"name\": \"世纪鹿园站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.96116943908527,40.610551502388404]}}";
        String data20 = "{\"region_type\": \"subway\", \"name\": \"文明路站\", \"region\": null, \"offset\": 0.00380, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.9675221111707,40.607155405220965]}}";
        String data21 = "{\"region_type\": \"subway\", \"name\": \"公路局站\", \"region\": null, \"offset\": 0.00400, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.98108466747084,40.59980950034273]}}";
        String data22 = "{\"region_type\": \"subway\", \"name\": \"豪德广场站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.98497227882001,40.59109928353652]}}";
        String data23 = "{\"region_type\": \"subway\", \"name\": \"西脑包站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [109.99684938675136,40.58695970056692]}}";
        String data24 = "{\"region_type\": \"subway\", \"name\": \"西河槽站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [110.00927763047275,40.58333223620315]}}";
        String data25 = "{\"region_type\": \"subway\", \"name\": \"公园路站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [110.01842117175835,40.58057877026462]}}";
        String data26 = "{\"region_type\": \"subway\", \"name\": \"包头东站\", \"region\": null, \"offset\": 0.00400, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [110.02529202028023,40.57246454128537]}}";
        String data27 = "{\"region_type\": \"subway\", \"name\": \"明航小区站\", \"region\": null, \"offset\": 0.00300, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [110.01985114891204,40.56630024567016]}}";
        String data28 = "{\"region_type\": \"subway\", \"name\": \"机场站\", \"region\": null, \"offset\": 0.00500, " +
                "\"location\": {\"type\": \"Point\", \"coordinates\": [110.01261093642484,40.5621427392887]}}";

        try {
            //删除已存在的表
            System.out.println("drop collection:exponent_region");
            exponentRegionCol.drop();
            //插入测试数据
            System.out.println("insert test data......");
            exponentRegionCol.insert(BasicDBObject.parse(data1));
            exponentRegionCol.insert(BasicDBObject.parse(data2));
            exponentRegionCol.insert(BasicDBObject.parse(data3));
            exponentRegionCol.insert(BasicDBObject.parse(data4));
            exponentRegionCol.insert(BasicDBObject.parse(data5));
            exponentRegionCol.insert(BasicDBObject.parse(data6));
            exponentRegionCol.insert(BasicDBObject.parse(data7));
            exponentRegionCol.insert(BasicDBObject.parse(data8));
            exponentRegionCol.insert(BasicDBObject.parse(data9));
            exponentRegionCol.insert(BasicDBObject.parse(data10));
            exponentRegionCol.insert(BasicDBObject.parse(data11));
            exponentRegionCol.insert(BasicDBObject.parse(data12));
            exponentRegionCol.insert(BasicDBObject.parse(data13));
            exponentRegionCol.insert(BasicDBObject.parse(data14));
            exponentRegionCol.insert(BasicDBObject.parse(data15));
            exponentRegionCol.insert(BasicDBObject.parse(data16));
            exponentRegionCol.insert(BasicDBObject.parse(data17));
            exponentRegionCol.insert(BasicDBObject.parse(data18));
            exponentRegionCol.insert(BasicDBObject.parse(data19));
            exponentRegionCol.insert(BasicDBObject.parse(data20));
            exponentRegionCol.insert(BasicDBObject.parse(data21));
            exponentRegionCol.insert(BasicDBObject.parse(data22));
            exponentRegionCol.insert(BasicDBObject.parse(data23));
            exponentRegionCol.insert(BasicDBObject.parse(data24));
            exponentRegionCol.insert(BasicDBObject.parse(data25));
            exponentRegionCol.insert(BasicDBObject.parse(data26));
            exponentRegionCol.insert(BasicDBObject.parse(data27));
            exponentRegionCol.insert(BasicDBObject.parse(data28));

            exponentRegionCol.createIndex("name");
            exponentRegionCol.createIndex("region_type");
            exponentRegionCol.createIndex("offset");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            mongoClient.close();
            System.out.println("process done!!");
        }
    }

    public static void main(String[] args) {
        MakeExponentLocationTestData mltd = new MakeExponentLocationTestData();
        mltd.makeTestData();
    }

}
